using System;
using Slaks.DocumentSerialization.Document;
using Slaks.DocumentSerialization.TermIdInfo;

namespace Slaks.Graphs.GraphBuilder.Extractor
{
    public class ExtractorBuilderNodesOnly : ExtractorBuilder
    {  
        protected override Graph Build(Document document, int numberOfVerticesToLeave, int nParameter, TermIdInfoMap map)
        {
			Graph graph = base.Build(document,numberOfVerticesToLeave,nParameter,map);
            string documentName = document.OriginalFileName;
            int index = documentName.LastIndexOfAny(new char[] { '\\', '/' });
            if (index >= 0 && (index + 1 < documentName.Length)) documentName = documentName.Substring(index + 1);

            graph.Name = documentName;
            Graph tempGraph = this.BuildTemporalGraph(document, BuilderType.ExtractorBuilderNodesOnly, numberOfVerticesToLeave,map);

            //Vertex vertex;
            graph = tempGraph;
            //iterate through nodes
            //foreach (Node node in document.Nodes)
            //{
            //    //check if the vertex is in the list of frequent nodes.
            //    if (tempGraph.GetVertex(node.Id) == null) continue;
            //    Section textSection = node.GetSectionByType(Section.SectionType.Text);
            //    if (textSection == null) continue;
            //    vertex = graph.CreateAddVertex(node.Id);

            //    vertex.Frequency = textSection.TermFrequency;

            //    //iterate through sentences
            //    foreach (Sentence sentence in textSection.Sentences)
            //    {
            //        AddRelations(document, graph, tempGraph, vertex, 1, 1, sentence, Section.SectionType.Text, BuilderType.SimpleRepresentationSchenker);
            //    }
            //}

            if (graph.GetVertexCount() < 0)
                throw new GraphException(String.Format("Length of the graph {0} is zero", documentName));

            return graph;
        }

    }
}